//导入request.js请求根据
import request from '@/utils/request.js'
//注意这里的函数需要向外暴露，要增加export
//提供调用注册接口的函数
export const userRegisterService = (registerData) =>{
    //默认时json格式传递对象
    //因为传递的格式为。。。使用需要借助URLSearchParams函数完成数据格式的转变
    var params = new URLSearchParams();
    for(let key in registerData){
        params.append(key,registerData[key]);
    }
    return request.post('/user/register',params);
} 

//提供调用登录接口的函数
export const userLoginService = (registerData) =>{
    var params = new URLSearchParams();
    for(let key in registerData){
        params.append(key,registerData[key]);
    }
    return request.post('/user/login',params);
}


//获取用户详细信息
export const userInfoService =() =>{
    return request.get('/user/userInfo')
}
//修改个人信息
export const userInfoUpdateService = (userInfo) =>{
    return request.put("/user/update",userInfo);
}

export const userAvatarUpdateService = (avatarUrl) =>{
    return request.patch('/user/updateAvatar?avatarUrl='+avatarUrl)
}

export const userPasswordUpdateService =(params) => {
    return request.patch('/user/updatePwd',params);
}

export const userLoginOutService = () =>{
    return request.post('/user/loginOut');
}

export const userSearchService = (params) => {
    return request.get('/user',{params:params})
}

export const userDeleteService =(id) => {
    return request.delete('/user?id='+id);
}

export const editorDeleteService =(id) => {
    return request.delete('/admin/editor?id='+id);
}

export const userUpdateStateService = (id,state) => {

    return request.put('/admin/user?id='+id+"&state="+state);
}

export const editorSearchService = (params) =>{
    return request.get('/editor/all',{params:params})
}

export const editorUpdateStateService = (id,state) =>{
    return request.put('/admin/editor?id='+id+"&state="+state);
}